package com.css.fxfzcpxx.modules.houseSeismicEvaluation.controller;


import com.alibaba.fastjson.JSONObject;
import com.css.fxfzcpxx.base.response.RestResponse;
import com.css.fxfzcpxx.modules.houseSeismicEvaluation.bo.GenerateVulnerabilityMatrixVo;
import com.css.fxfzcpxx.modules.houseSeismicEvaluation.entity.BuildingStructureParam;
import com.css.fxfzcpxx.modules.houseSeismicEvaluation.service.HouSeiEvaluationService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * @author
 * @program
 * @description
 * @create 2022/8/8 10:39
 **/
@RestController
@RequestMapping("/houSeiEvaluation")
@Slf4j
public class HouSeiEvaluationController {
    @Resource
    HouSeiEvaluationService houSeiEvaluationService;


    /**
     *
     * 获取破坏状态列表信息
     * @param param
     * @return
     */
    @PostMapping("/getData")
    public RestResponse getData(@RequestBody BuildingStructureParam param) {
        RestResponse response = null;
        try {
            HashMap<String, List<GenerateVulnerabilityMatrixVo>> list=houSeiEvaluationService.getData(param);
            response = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = e.getMessage();
            if(StringUtils.isBlank(errormessage)) {
                errormessage = "获取失败";
            }
            log.error(errormessage,e);
            response=RestResponse.fail(errormessage);
        }
        return response;
    }

    /**
     * 保存
     * @param generateVulnerabilityMatrixVo
     * @return
     */
    @PostMapping("/save")
    public RestResponse save(@RequestBody GenerateVulnerabilityMatrixVo generateVulnerabilityMatrixVo){
        RestResponse restResponse=null;
        JSONObject jsonObject=new JSONObject();
        try{
            houSeiEvaluationService.save(generateVulnerabilityMatrixVo);
            jsonObject.put("message","保存成功");
            restResponse= RestResponse.succeed(jsonObject);
        }catch (Exception e){
            String errormessage="保存失败";
            log.error(errormessage,e);
            restResponse= RestResponse.fail(errormessage);
        }
        return restResponse;
    }
}
